
package info.dani.struts.hola;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Daniel Lacasta
 *
 */
public class greetNTimes extends ActionSupport {
	
    private String greet = "";
    private int times = 0;
    private String result = "";
    
    public void validate() {
    	if (greet.length() ==0){
    		addFieldError("greet", "Write something");
    	}
    	if (times < 1 ){
    		addFieldError("times", "Write something");
    	}
    	
    }
    
	public String getGreet() {
		return greet;
	}

	public void setGreet(String greet) {
		this.greet = greet;
	}

	public int getTimes() {
		return times;
	}

	public void setTimes(int times) {
		this.times = times;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	@Override
    public String execute()
    {
    	for (int i =0; i< times;i++){
    		result += greet + "<br />";
    	}
        
        return SUCCESS;
    }
    
  
}